package com.lam.smartbutlerv4.ui;
/*
 *  project name:       SmartButlerV5
 *  pakcage name:       com.lam.smartbutlerv4.ui
 *  file name:          ColesCLD1
 *  create date:        2019/2/17 21:20
 *  creator:            Luan Xiyuan
 *  description:        TODO
 */

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import com.lam.smartbutlerv4.R;
import com.lam.smartbutlerv4.service.card.CardFragment;
import com.lam.smartbutlerv4.service.card.CardFragmentPagerAdapter;
import com.lam.smartbutlerv4.service.card.CardItem;
import com.lam.smartbutlerv4.service.card.CardPagerAdapter;
import com.lam.smartbutlerv4.service.card.ShadowTransformer;
import com.lam.smartbutlerv4.utils.StatusBarUtils;

public class ColesACR1 extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, CardFragment.CallBackValue {

    private Button btn_coles_acr1_continue, btn_coles_acr1_back_to_home;
//    private TextView tv_coles_acr1_current_creditlimit;
    private ViewPager mViewPager;
    private SeekBar sb_coles_acr1_new_creditlimit;
    private TextView tv_coles_acr1_new_creditlimit;

    private CardPagerAdapter mCardAdapter;
    private ShadowTransformer mCardShadowTransformer;
    private CardFragmentPagerAdapter mFragmentCardAdapter;
    private ShadowTransformer mFragmentCardShadowTransformer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coles_acr1);

        initView();
    }

    private void initView() {
        StatusBarUtils.setWindowStatusBarColor(this, R.color.bg_toolbar_default);

        btn_coles_acr1_continue = findViewById(R.id.btn_coles_acr1_continue);
        btn_coles_acr1_continue.setOnClickListener(this);

        btn_coles_acr1_back_to_home = findViewById(R.id.btn_coles_acr1_back_to_home);
        btn_coles_acr1_back_to_home.setOnClickListener(this);

        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        mCardAdapter = new CardPagerAdapter();
        mCardAdapter.addCardItem(new CardItem(R.string.title_11, R.string.text_1, R.drawable.card1, R.string.cardnumber_1, Float.parseFloat(this.getString(R.string.current_creditlimit_1))));
        mCardAdapter.addCardItem(new CardItem(R.string.title_21, R.string.text_1, R.drawable.card2, R.string.cardnumber_2, Float.parseFloat(this.getString(R.string.current_creditlimit_2))));
        mCardAdapter.addCardItem(new CardItem(R.string.title_31, R.string.text_1, R.drawable.card3, R.string.cardnumber_3, Float.parseFloat(this.getString(R.string.current_creditlimit_3))));
        mCardAdapter.addCardItem(new CardItem(R.string.title_41, R.string.text_1, R.drawable.card4, R.string.cardnumber_4, Float.parseFloat(this.getString(R.string.current_creditlimit_4))));
        mCardAdapter.addCardItem(new CardItem(R.string.title_41, R.string.text_1, R.drawable.card5, R.string.cardnumber_5, Float.parseFloat(this.getString(R.string.current_creditlimit_5))));
        mFragmentCardAdapter = new CardFragmentPagerAdapter(getSupportFragmentManager(),
                dpToPixels(2, this));

        mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter);
        mFragmentCardShadowTransformer = new ShadowTransformer(mViewPager, mFragmentCardAdapter);
        mCardShadowTransformer.enableScaling(true);
        mFragmentCardShadowTransformer.enableScaling(true);

        mViewPager.setAdapter(mCardAdapter);
        mViewPager.setPageTransformer(false, mCardShadowTransformer);
        mViewPager.setOffscreenPageLimit(3);

        sb_coles_acr1_new_creditlimit = findViewById(R.id.sb_coles_acr1_new_creditlimit);
        sb_coles_acr1_new_creditlimit.setOnSeekBarChangeListener(this);
        sb_coles_acr1_new_creditlimit.setMax(99999);
        sb_coles_acr1_new_creditlimit.setProgress(50000);

        tv_coles_acr1_new_creditlimit = findViewById(R.id.tv_coles_acr1_new_creditlimit);
        tv_coles_acr1_new_creditlimit.setText(50000+"");

//        tv_coles_acr1_current_creditlimit = findViewById(R.id.tv_coles_acr1_current_creditlimit);
//        NumAnim.startAnim(tv_coles_acr1_current_creditlimit, (float) 35500.00, 1000);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_coles_acr1_continue:
                startActivity(new Intent(ColesACR1.this, ColesACR2.class));
                break;
            case R.id.btn_coles_acr1_back_to_home:
                startActivity(new Intent(ColesACR1.this, CitiHome.class));
                break;
        }
    }

    public static float dpToPixels(int dp, Context context) {
        return dp * (context.getResources().getDisplayMetrics().density);
    }

    //back forbidden
    @Override
    public void onBackPressed() {
//        super.onBackPressed();
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//        sb_coles_acr1_new_creditlimit.setProgress(99999);
        if(tv_coles_acr1_new_creditlimit != null) {
            tv_coles_acr1_new_creditlimit.setText(progress+"");
        }
    }

    @Override
    public void sendMessageValue(String strValue) {
        tv_coles_acr1_new_creditlimit.setText(strValue);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}
